/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


/**
 *
 * @author ntomio
 */

public class Client extends Thread {
  
    private Buffer buffer;
    
    Client(Buffer buffer)
    {
        this.buffer = buffer;
      
    }
    
    @Override
   public void run()
    {
        try
        {
            Socket socket = null;
            ObjectOutputStream fluxDeSortie = null;
            
            while (true)
            {
               
                socket = new Socket (InetAddress.getByName("localhost"), 8080);
                fluxDeSortie = new ObjectOutputStream (socket.getOutputStream());
                //String str = new String(buffer.getElementTampon());
                //System.out.println(str);
                fluxDeSortie.writeObject (this.buffer.getElementTampon());
                socket.close();
            }
        }
        catch (ConnectException e)
        {
            System.err.println(e.getMessage());
        }
        catch (UnknownHostException e)
        {
            System.err.println(e.getMessage());
        }
        catch (IOException e)
        {
            System.err.println(e.getMessage());
        }
    }
}
